home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr46 / vfwdk.zip / VFWSDK.ZIP / SAMPLES / BRAVADO / DRVPROC.C < prev    next >
C/C++ Source or Header  |  1993-01-31  |  11KB  |  315 lines

  1. /****************************************************************************
  2.  *
  3.  *   drvproc.c
  4.  * 
  5.  *   Driver Entry Point 
  6.  *
  7.  *   Microsoft Video for Windows Sample Capture Driver
  8.  *   
  9.  *
  10.  *   Copyright (c) 1992-1993 Microsoft Corporation.  All Rights Reserved.
  11.  *
  12.  *    You have a royalty-free right to use, modify, reproduce and 
  13.  *    distribute the Sample Files (and/or any modified version) in 
  14.  *    any way you find useful, provided that you agree that 
  15.  *    Microsoft has no warranty obligations or liability for any 
  16.  *    Sample Application Files which are modified. 
  17.  *
  18.  ***************************************************************************/
  19.  
  20. #include <windows.h>
  21. #include <mmsystem.h>
  22. #include <msvideo.h>
  23. #include <msviddrv.h>
  24. #include "ct.h"
  25. #include "config.h"
  26. #include "debug.h"
  27.  
  28. /* This sample driver includes support for the Installable Compressor
  29.    interface.  To create a combined capture and codec driver, define
  30.    _CODEC_SUPPORT to be "1" in the following statement.
  31. */
  32. #define _CODEC_SUPPORT  0
  33.  
  34. #if _CODEC_SUPPORT
  35. #include <compddk.h> 
  36. #include <compman.h> 
  37. #include "icsample.h"   // This file may have been renamed, modified
  38. LRESULT FAR PASCAL _loadds DriverProcCodec(DWORD dwDriverID, 
  39.         HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2);
  40. #endif
  41.  
  42. extern BOOL fVideoOpen;
  43.  
  44. //
  45. //  we use this driverID to determine when we where opened as a video
  46. //  device or from the control panel, etc....
  47. //
  48. #define BOGUS_DRIVER_ID     1
  49.  
  50. /*
  51. DriverProc  The entry point for an installable driver.
  52.                 
  53. DWORD dwDriverId  For most messages, dwDriverId is the DWORD
  54.       value that the driver returns in response to a DRV_OPEN message.
  55.       Each time that the driver is opened, through the DrvOpen API,
  56.       the driver receives a DRV_OPEN message and can return an
  57.       arbitrary, non-zero value. The installable driver interface
  58.       saves this value and returns a unique driver handle to the 
  59.       application. Whenever the application sends a message to the
  60.       driver using the driver handle, the interface routes the message
  61.       to this entry point and passes the corresponding dwDriverId.
  62.       This mechanism allows the driver to use the same or different
  63.       identifiers for multiple opens but ensures that driver handles
  64.       are unique at the application interface layer.
  65.  
  66.       The following messages are not related to a particular open
  67.       instance of the driver. For these messages, the dwDriverId
  68.       will always be zero.
  69.  
  70.           DRV_LOAD, DRV_FREE, DRV_ENABLE, DRV_DISABLE, DRV_OPEN
  71.  
  72. HDRVR  hDriver  This is the handle returned to the
  73.       application by the driver interface.
  74.            
  75. UINT  uiMessage  The requested action to be performed. Message
  76.       values below DRV_RESERVED are used for globally defined messages.
  77.       Message values from DRV_RESERVED to DRV_USER are used for
  78.       defined driver protocols. Messages above DRV_USER are used
  79.       for driver specific messages.
  80.  
  81. LPARAM  lParam1  Data for this message.  Defined separately for
  82.       each message
  83.  
  84. LPARAM  lParam2  Data for this message.  Defined separately for
  85.       each message
  86.  
  87. Returns: Defined separately for each message. 
  88. */
  89.  
  90. LRESULT FAR PASCAL _loadds DriverProc(DWORD dwDriverID, HDRVR hDriver, UINT uiMessage, LPARAM lParam1, LPARAM lParam2)
  91. {
  92.  
  93. #if _CODEC_SUPPORT
  94.     if (dwDriverID && (dwDriverID != BOGUS_DRIVER_ID)) {
  95.         if (((PINSTINFO) dwDriverID) -> fccType == ICTYPE_VIDEO)
  96.             return DriverProcCodec (dwDriverID, hDriver, uiMessage, 
  97.                 lParam1, lParam2);
  98.     }
  99. #endif
  100.  
  101.     switch (uiMessage)
  102.     {
  103.         case DRV_LOAD:
  104.             D1("DRV_LOAD");
  105.  
  106.             /*
  107.                Sent to the driver when it is loaded. Always the first
  108.                message received by a driver.
  109.  
  110.                dwDriverID is 0L. 
  111.                lParam1 is 0L.
  112.                lParam2 is 0L.
  113.                 
  114.                Return 0L to fail the load.
  115.  
  116.                DefDriverProc will return NON-ZERO so we don't have to
  117.                handle DRV_LOAD
  118.             */
  119.  
  120.             return (LRESULT)1L;
  121.  
  122.         case DRV_FREE:
  123.             D1("DRV_FREE");
  124.  
  125.             /*
  126.                Sent to the driver when it is about to be discarded. This
  127.                will always be the last message received by a driver before
  128.                it is freed. 
  129.  
  130.                dwDriverID is 0L. 
  131.                lParam1 is 0L.
  132.                lParam2 is 0L.
  133.                 
  134.                Return value is ignored.
  135.             */
  136.  
  137.             return (LRESULT)1L;
  138.  
  139.         case DRV_OPEN:
  140.             D1("DRV_OPEN");
  141.              
  142.             /*
  143.                Sent to the driver when it is opened. 
  144.  
  145.                dwDriverID is 0L.
  146.                
  147.                lParam1 is a far pointer to a zero-terminated string
  148.                containing the name used to open the driver.
  149.                
  150.                lParam2 is passed through from the drvOpen call. It is
  151.                NULL if this open is from the Drivers Applet in control.exe
  152.                It is LPVIDEO_OPEN_PARMS otherwise.
  153.                 
  154.                Return 0L to fail the open.
  155.  
  156.                DefDriverProc will return ZERO so we do have to
  157.                handle the DRV_OPEN message.
  158.              */
  159.  
  160.             //
  161.             //  if we were opened without a open structure then just
  162.             //  return a phony (non zero) id so the OpenDriver() will
  163.             //  work.
  164.             //
  165.             if (lParam2 == NULL)
  166.                 return BOGUS_DRIVER_ID;
  167.  
  168. #if _CODEC_SUPPORT
  169.             if (((ICOPEN FAR *) lParam2) -> fccType == ICTYPE_VIDEO)
  170.                 return DriverProcCodec (dwDriverID, hDriver, uiMessage, 
  171.                         lParam1, lParam2);
  172. #endif
  173.             //  Verify this open is for us, and not for an installable
  174.             //  codec.
  175.             if (((LPVIDEO_OPEN_PARMS) lParam2) -> fccType != OPEN_TYPE_VCAP)
  176.                 return 0L;
  177.  
  178.             return (DWORD)(WORD)
  179.                 VideoOpen ((LPVIDEO_OPEN_PARMS) lParam2);
  180.  
  181.         case DRV_CLOSE:
  182.             D1("DRV_CLOSE");
  183.  
  184.             /*
  185.                Sent to the driver when it is closed. Drivers are unloaded
  186.                when the close count reaches zero. 
  187.  
  188.                dwDriverID is the driver identifier returned from the
  189.                corresponding DRV_OPEN.
  190.                
  191.                lParam1 is passed through from the drvClose call.
  192.  
  193.                lParam2 is passed through from the drvClose call.
  194.                 
  195.                Return 0L to fail the close.
  196.  
  197.                DefDriverProc will return ZERO so we do have to
  198.                handle the DRV_CLOSE message.
  199.             */
  200.  
  201.             if (dwDriverID == BOGUS_DRIVER_ID || dwDriverID == 0)
  202.                 return 1L;      // return success
  203.  
  204.             return ((VideoClose((PCHANNEL)dwDriverID) == DV_ERR_OK) ? 1L : 0);
  205.            
  206.         case DRV_ENABLE:
  207.             D1("DRV_ENABLE");
  208.  
  209.             /*
  210.                Sent to the driver when the driver is loaded or reloaded
  211.                and whenever Windows is enabled. Drivers should only
  212.                hook interrupts or expect ANY part of the driver to be in
  213.                memory between enable and disable messages
  214.  
  215.                dwDriverID is 0L. 
  216.                lParam1 is 0L.
  217.                lParam2 is 0L.
  218.                 
  219.                Return value is ignored.
  220.             */
  221. //            if( fVideoOpen )
  222. //                IRQEnable();
  223.             return (LRESULT)1L;
  224.  
  225.         case DRV_DISABLE:
  226.             D1("DRV_DISABLE");
  227.  
  228.             /*
  229.                Sent to the driver before the driver is freed.
  230.                and whenever Windows is disabled
  231.  
  232.                dwDriverID is 0L. 
  233.                lParam1 is 0L.
  234.                lParam2 is 0L.
  235.                 
  236.                Return value is ignored.
  237.             */
  238.  
  239. //            if( fVideoOpen )
  240. //                IRQDisable();
  241.             return (LRESULT)1L;
  242.  
  243.         case DRV_QUERYCONFIGURE:
  244.             D1("DRV_QUERYCONFIGURE");
  245.  
  246.             /*
  247.                 Sent to the driver so that applications can
  248.                 determine whether the driver supports custom
  249.                 configuration. The driver should return a
  250.                 non-zero value to indicate that configuration
  251.                 is supported.
  252.                 
  253.                 dwDriverID is the value returned from the DRV_OPEN
  254.                 call that must have succeeded before this message
  255.                 was sent.
  256.  
  257.                 lParam1 is passed from the app and is undefined.
  258.                 lParam2 is passed from the app and is undefined.
  259.  
  260.                 Return 0L to indicate configuration NOT supported.
  261.             */
  262.  
  263.             return (LRESULT)1L;        // we do configuration
  264.  
  265.         case DRV_CONFIGURE:
  266.             D1("DRV_CONFIGURE");
  267.  
  268.             /*
  269.                 Sent to the driver so that it can display a custom
  270.                 configuration dialog box.
  271.  
  272.                 lParam1 is passed from the app. and should contain
  273.                 the parent window handle in the loword.
  274.                 lParam2 is passed from the app and is undefined.
  275.  
  276.                 Return value is undefined.
  277.  
  278.                 Drivers should create their own section in system.ini.
  279.                 The section name should be the driver name.
  280.             */
  281.  
  282.             return (LRESULT)Config((HWND)lParam1, ghModule);
  283.  
  284.         case DRV_INSTALL:
  285.             D1("DRV_INSTALL");
  286.             /*
  287.                 Windows has installed the driver, and since we
  288.                 are loaded on demand, there is no need to 
  289.                 restart Windows.
  290.             */
  291.             return (LRESULT)DRV_OK;
  292.  
  293.         case DRV_REMOVE:
  294.             D1("DRV_REMOVE");
  295.             ConfigRemove();
  296.             return (LRESULT)DRV_OK;
  297.  
  298.         case DVM_GETVIDEOAPIVER: /* lParam1 = LPDWORD */
  299.              if (lParam1) {
  300.                  *(LPDWORD) lParam1 = VIDEOAPIVERSION;
  301.                  return DV_ERR_OK;
  302.              }
  303.              else
  304.                 return DV_ERR_PARAM1;
  305.  
  306.         default:
  307.             if (dwDriverID == BOGUS_DRIVER_ID || dwDriverID == 0)
  308.                 return DefDriverProc(dwDriverID, hDriver, uiMessage,lParam1,lParam2);
  309.  
  310.             // FIX, check range?
  311.             return VideoProcessMessage((PCHANNEL)dwDriverID, uiMessage, lParam1, lParam2);
  312.     }
  313. }
  314.  
  315.